package com.wlcj.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.alibaba.dubbo.common.utils.StringUtils;

public class Lang {
	
	public static final int DEFAULT_PRECISION = 2;
	
	public static String formatMoney(BigDecimal b, int len) {
		return b.setScale(len, RoundingMode.HALF_DOWN).toString();
	}
	
	public static String formatMoney(BigDecimal b) {
		return formatMoney(b, DEFAULT_PRECISION);
	}
	
	public static String formatMoney(double b, int len) {
		return formatMoney(new BigDecimal(b), len);
	}
	
	public static String formatMoney(double b) {
		return formatMoney(new BigDecimal(b), DEFAULT_PRECISION);
	}
	
	public static int toInt(Object obj) {
		return obj==null||StringUtils.isBlank(obj+"")?0:Integer.parseInt(obj+"");
	}
	
	public static String getTimeStamp10() {
		String timestamp = System.currentTimeMillis()+"";
		return timestamp.substring(0, 10);
	}
	
	public static void main(String[] args) {
//		System.out.println(formatMoney(new BigDecimal("12.456"), 2));
//		System.out.println(formatMoney(new BigDecimal("0"), 2));
	}

}
